/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Frmcomprobante.java
 *
 * Created on 29/05/2011, 13:35:05
 */

package logano;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import loganosystem.contrato.Comprobante;
import util.Helper;

/**
 *
 * @author loreh
 */
public class Frmcomprobante extends FrmBaseEdicion {

    Comprobante comprobante = new Comprobante();

    /** Creates new form Frmcomprobante */
    public Frmcomprobante() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtnºcomprobante = new javax.swing.JLabel();
        txtfecha_emision = new javax.swing.JLabel();
        txtcancelado = new javax.swing.JLabel();
        txtfecha_cancelado = new javax.swing.JLabel();
        tbncomprobante = new javax.swing.JTextField();
        btaceptar = new javax.swing.JButton();
        btlimpiar = new javax.swing.JButton();
        btcancelar = new javax.swing.JButton();
        tbfecha_emision = new javax.swing.JFormattedTextField();
        tbfecha_cancelado = new javax.swing.JFormattedTextField();
        ckCancelado = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(logano.LoganoApp.class).getContext().getResourceMap(Frmcomprobante.class);
        txtnºcomprobante.setText(resourceMap.getString("txtnºcomprobante.text")); // NOI18N
        txtnºcomprobante.setName("txtnºcomprobante"); // NOI18N

        txtfecha_emision.setText(resourceMap.getString("txtfecha_emision.text")); // NOI18N
        txtfecha_emision.setName("txtfecha_emision"); // NOI18N

        txtcancelado.setText(resourceMap.getString("txtcancelado.text")); // NOI18N
        txtcancelado.setName("txtcancelado"); // NOI18N

        txtfecha_cancelado.setText(resourceMap.getString("txtfecha_cancelado.text")); // NOI18N
        txtfecha_cancelado.setName("txtfecha_cancelado"); // NOI18N

        tbncomprobante.setText(resourceMap.getString("tbncomprobante.text")); // NOI18N
        tbncomprobante.setName("tbncomprobante"); // NOI18N
        tbncomprobante.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbncomprobanteKeyPressed(evt);
            }
        });

        btaceptar.setText(resourceMap.getString("btaceptar.text")); // NOI18N
        btaceptar.setName("btaceptar"); // NOI18N
        btaceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btaceptarActionPerformed(evt);
            }
        });

        btlimpiar.setText(resourceMap.getString("btlimpiar.text")); // NOI18N
        btlimpiar.setName("btlimpiar"); // NOI18N
        btlimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btlimpiarActionPerformed(evt);
            }
        });

        btcancelar.setText(resourceMap.getString("btcancelar.text")); // NOI18N
        btcancelar.setName("btcancelar"); // NOI18N
        btcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btcancelarActionPerformed(evt);
            }
        });

        tbfecha_emision.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT))));
        tbfecha_emision.setText(resourceMap.getString("tbfecha_emision.text")); // NOI18N
        tbfecha_emision.setName("tbfecha_emision"); // NOI18N
        tbfecha_emision.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbfecha_emisionKeyPressed(evt);
            }
        });

        tbfecha_cancelado.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT))));
        tbfecha_cancelado.setName("tbfecha_cancelado"); // NOI18N
        tbfecha_cancelado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbfecha_canceladoKeyPressed(evt);
            }
        });

        ckCancelado.setText(resourceMap.getString("ckCancelado.text")); // NOI18N
        ckCancelado.setName("ckCancelado"); // NOI18N
        ckCancelado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ckCanceladoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtnºcomprobante)
                                .addGap(18, 18, 18)
                                .addComponent(tbncomprobante, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtfecha_cancelado)
                                    .addComponent(txtcancelado)
                                    .addComponent(txtfecha_emision))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(ckCancelado)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(tbfecha_cancelado, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
                                        .addComponent(tbfecha_emision, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(btaceptar)
                        .addGap(18, 18, 18)
                        .addComponent(btlimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btcancelar)))
                .addGap(79, 79, 79))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtnºcomprobante)
                    .addComponent(tbncomprobante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtfecha_emision)
                    .addComponent(tbfecha_emision, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtcancelado)
                    .addComponent(ckCancelado))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtfecha_cancelado)
                    .addComponent(tbfecha_cancelado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btlimpiar)
                    .addComponent(btcancelar)
                    .addComponent(btaceptar))
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btaceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btaceptarActionPerformed
        
    }//GEN-LAST:event_btaceptarActionPerformed

    private void btlimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btlimpiarActionPerformed

        txtnºcomprobante.setText("");
        txtfecha_emision.setText("");
        txtcancelado.setText("");
        txtfecha_cancelado.setText("");



    }//GEN-LAST:event_btlimpiarActionPerformed

    @Override
    protected Comprobante getValues() throws ParseException
    {
        this.comprobante.setCancelado(ckCancelado.isSelected());
        this.comprobante.setFecha_cancelado(Helper.parseString(tbfecha_cancelado.getText()));
        this.comprobante.setFecha_emision(Helper.parseString(tbfecha_emision.getText()));
        this.comprobante.setNro_comprobante(Long.parseLong(tbncomprobante.getText()));
        return comprobante;
    }

     @Override
    protected void setValues()
    {
        this.ckCancelado.setSelected(this.comprobante.isCancelado());
        this.tbfecha_cancelado.setText(String.valueOf( this.comprobante.getFecha_cancelado()));
        this.tbncomprobante.setText(String.valueOf(this.comprobante.getNro_comprobante()));
        this.tbfecha_emision.setText(this.comprobante.getFecha_emision().toString());
    }



    private void btcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btcancelarActionPerformed

        dispose();
    }//GEN-LAST:event_btcancelarActionPerformed

    private void tbncomprobanteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbncomprobanteKeyPressed
         Helper.enterKeyPressed(evt, tbfecha_emision);
    }//GEN-LAST:event_tbncomprobanteKeyPressed

    private void tbfecha_emisionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbfecha_emisionKeyPressed
        Helper.enterKeyPressed(evt, tbfecha_cancelado);
    }//GEN-LAST:event_tbfecha_emisionKeyPressed

    private void ckCanceladoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ckCanceladoMouseClicked
       
    }//GEN-LAST:event_ckCanceladoMouseClicked

    private void tbfecha_canceladoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbfecha_canceladoKeyPressed
         Helper.enterKeyPressed(evt, tbncomprobante);
    }//GEN-LAST:event_tbfecha_canceladoKeyPressed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frmcomprobante().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btaceptar;
    private javax.swing.JButton btcancelar;
    private javax.swing.JButton btlimpiar;
    private javax.swing.JCheckBox ckCancelado;
    private javax.swing.JFormattedTextField tbfecha_cancelado;
    private javax.swing.JFormattedTextField tbfecha_emision;
    private javax.swing.JTextField tbncomprobante;
    private javax.swing.JLabel txtcancelado;
    private javax.swing.JLabel txtfecha_cancelado;
    private javax.swing.JLabel txtfecha_emision;
    private javax.swing.JLabel txtnºcomprobante;
    // End of variables declaration//GEN-END:variables

}
